//
//  ValmMindset.swift
//  HIextractLicve
//
//  Created by HIextractLicve on 2024/12/9.
//

import UIKit
import ProgressHUD
class ValmMindset: UIViewController ,UITextViewDelegate{

    @IBOutlet weak var minwpostnameTHL: UILabel!
    @IBOutlet weak var postmineHTlimg: UIImageView!
    var eachVioViewHTLC:THLCNOrBUTTOn?
    var mindfulnessPageHTL:THLCNPageControll?
    var journeyHTLC:UIView?
    
    @IBOutlet weak var enterSayTExfHTL: UITextView!
    
    @IBOutlet weak var appimgzero: UIImageView!
    
    @IBOutlet weak var appimgone: UIImageView!
    @IBOutlet weak var appimgtwo: UIImageView!
    
    
    var pickimgelistTHL:Array<UIImage> = Array<UIImage>()
    
    override func viewDidLoad() {
        super.viewDidLoad()

        postmineHTlimg.layer.cornerRadius = 20
        postmineHTlimg.layer.masksToBounds = true
        postmineHTlimg.image = HTLCAllDealRelaxing.Relaxing.showingHTLimgHead
        if self.navigationController?.navigationBar.isHidden == true {
            journeyHTLC?.alpha = 1
            journeyHTLC?.layer.cornerRadius = 12
        }
        journeyHTLC?.backgroundColor = UIColor(red: 0.06, green: 0.07, blue: 0.07, alpha: 0.01)

        eachVioViewHTLC = THLCNOrBUTTOn.init()
        eachVioViewHTLC?.setTitle("anchors", for: .normal)
        if journeyHTLC != nil {
            journeyHTLC?.addSubview(eachVioViewHTLC ?? THLCNOrBUTTOn.init())
            view.addSubview(journeyHTLC!)
        }

        mindfulnessPageHTL = THLCNPageControll()
        mindfulnessPageHTL?.numberOfPages = 1
        mindfulnessPageHTL?.backgroundColor = UIColor(red: 0.06, green: 0.07, blue: 0.07, alpha: 0.01)
        mindfulnessPageHTL?.tintColor = UIColor(red: 0.06, green: 0.07, blue: 0.07, alpha: 0.01)
        mindfulnessPageHTL?.sizeToFit()

        if journeyHTLC != nil {
            journeyHTLC?.addSubview(mindfulnessPageHTL ?? THLCNPageControll.init())
           
        }

        minwpostnameTHL.text = HTLCAllDealRelaxing.Relaxing.signinUserDataHTL["HTLCkiName"]
        enterSayTExfHTL.delegate = self
        
    }


    @IBAction func Funrightnoweback(_ sender: Any) {
       
            self.navigationController?.popViewController(animated: true)
        
        
    }

    
    
    func textViewDidBeginEditing(_ textView: UITextView) {
       
            textView.text = nil
        
       
    }
    
    @IBAction func relaeasrClickTHLC(_ sender: Any) {
      
        
        
        guard let rovbertDescd = enterSayTExfHTL.text,rovbertDescd.count != 0, "Share the dynamics of the moment…".contains(rovbertDescd) == false else {
            
            
                ProgressHUD.banner("Your post description must be filled in!!!", HTLROOOMMeasg.BinrwetioBase64("QSBwcm9tcHQgbWVzc2FnZQ=="), delay: 2.0)
            
            return
        }
        
        if self.pickimgelistTHL.count == 0 {
            
            
            
                ProgressHUD.banner("Your post Image should be added!!！", HTLROOOMMeasg.BinrwetioBase64("QSBwcm9tcHQgbWVzc2FnZQ=="), delay: 2.0)
            
            return
        }
        
        ProgressHUD.animate("")
        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 1.5, execute: DispatchWorkItem(block: {
            
           
                ProgressHUD.succeed(HTLROOOMMeasg.BinrwetioBase64("VXBsb2FkIHN1Y2Nlc3NmdWwsIHlvdXIgdXBkYXRlcyB3aWxsIGJlIGRpc3BsYXllZCBhZnRlciByZXZpZXfvvIE="), delay: 2.5)
            
           
            self.navigationController?.popViewController(animated: true)
        }))
    }
    
    
    @IBAction func getsourceImg(_ sender: Any) {
        
        if self.pickimgelistTHL.count > 3 {
            
            ProgressHUD.banner(" Sorry,Add up to three images!!!", HTLROOOMMeasg.BinrwetioBase64("QSBwcm9tcHQgbWVzc2FnZQ=="), delay: 2.0)
            
            return
        }
        
      
      
        //take
        if UIImagePickerController.isSourceTypeAvailable(.camera) {
            let photoPicker = UIImagePickerController()
            photoPicker.delegate = self
            photoPicker.allowsEditing = false
            
           
                photoPicker.sourceType = .camera
            
            
  
            self.present(photoPicker, animated: true, completion: nil)
            
        }else {
            
           
                ProgressHUD.banner(HTLROOOMMeasg.BinrwetioBase64("U29ycnksTm8gYWxidW0gcGVybWlzc2lvbg=="), HTLROOOMMeasg.BinrwetioBase64("QSBwcm9tcHQgbWVzc2FnZQ=="), delay: 2.0)
            
            
          
        }
    }
    
    
    
    @IBAction func imgTogetImg(_ sender: Any) {
        
        if self.pickimgelistTHL.count > 3 {
            
            ProgressHUD.banner(HTLROOOMMeasg.BinrwetioBase64("U29ycnksQWRkIHVwIHRvIHRocmVlIGltYWdlcw=="), HTLROOOMMeasg.BinrwetioBase64("QSBwcm9tcHQgbWVzc2FnZQ=="), delay: 2.0)
            
            return
        }
      
       
        //img
        if UIImagePickerController.isSourceTypeAvailable(.photoLibrary) {
            let photoPicker = UIImagePickerController()
            photoPicker.delegate = self
            photoPicker.allowsEditing = false
            
            
                photoPicker.sourceType = .photoLibrary
            
            
  
            self.present(photoPicker, animated: true, completion: nil)
            
        }else {
            
            
                ProgressHUD.banner(HTLROOOMMeasg.BinrwetioBase64("U29ycnksTm8gYWxidW0gcGVybWlzc2lvbg=="), HTLROOOMMeasg.BinrwetioBase64("QSBwcm9tcHQgbWVzc2FnZQ=="), delay: 2.0)
            
           
          
        }
    }
    
    
}
extension  ValmMindset :UINavigationControllerDelegate, UIImagePickerControllerDelegate{
   
    
    func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
      
            picker.dismiss(animated: true)
        
       
    }
    
    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
      
       
        if let image : UIImage = info[UIImagePickerController.InfoKey.originalImage] as? UIImage{
            DispatchQueue.main.async {
                picker.dismiss(animated: true)
               
                    self.pickimgelistTHL.append(image)
                
                
               
                
                if self.pickimgelistTHL.count == 1 {
                    self.appimgzero.image = self.pickimgelistTHL[0]
                    
                }
                
                if self.pickimgelistTHL.count == 2 {
                    self.appimgzero.image = self.pickimgelistTHL[0]
                    self.appimgone.image = self.pickimgelistTHL[1]
                }
                
                if self.pickimgelistTHL.count == 3 {
                    self.appimgzero.image = self.pickimgelistTHL[0]
                    self.appimgone.image = self.pickimgelistTHL[1]
                    
                    self.appimgtwo.image = self.pickimgelistTHL[2]
                }
            }
        }
       
       
        
    }
}
